package cn.kgc.vue.service.impl;

import cn.kgc.vue.commons.QueryCondition;
import cn.kgc.vue.commons.ResponseResult;
import cn.kgc.vue.entity.Schedule;
import cn.kgc.vue.mapper.ScheduleMapper;
import cn.kgc.vue.service.ScheduleService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
* @author mengshun
* @description 针对表【sys_schedule】的数据库操作Service实现
* @createDate 2023-12-15 10:40:55
*/
@Service
public class ScheduleServiceImpl extends ServiceImpl<ScheduleMapper, Schedule> implements ScheduleService{


    @Override
    public ResponseResult getScheduleList(QueryCondition<Schedule> queryCondition) {

        Page<Schedule> schedulePage = new Page<>(queryCondition.getPage(), queryCondition.getLimit());

        LambdaQueryWrapper<Schedule> lambda = new QueryWrapper<Schedule>().lambda();
        lambda.eq(ObjectUtils.isNotNull(queryCondition.getQuery().getClassTime()),Schedule::getClassTime,queryCondition.getQuery().getClassTime() );

        baseMapper.selectPage(schedulePage,lambda);

        HashMap<String, Object> result = new HashMap<>();
        result.put("total",schedulePage.getTotal());
        result.put("pageData",schedulePage.getRecords());

        return ResponseResult.success().data(result);
    }
}




